#include "dataanalysis.h"
#include "nlink_linktrack_anchorframe0.h"
#include "config.h"
#include "bsp_usart.h"
#include "data_process.h"
#include "crc8.h"

uint8_t speaker_flag = 0;
//void Speaker_prase(uint8_t buf[])
//{
//	if(buf[0]==0X0A&&buf[1]==0X01&&buf[2]==0X0E)
//	{
//		speaker_flag = 1;		
//	}
//	else if(buf[0]==0X0A&&buf[1]==0X00&&buf[2]==0X0E)
//	{
//		speaker_flag = 0;
//	}
//}



void RF433_task(void)
{
	static uint8_t runcnt = 0;
	uint8_t cnt = 0;
	
	
	uint8_t buf[64] = {0};
	buf[cnt++] = 0XF1;                //0
	buf[cnt++] = 0X01;								//1 
	buf[cnt++] = 0X0D;								//2 Length..
	buf[cnt++] = C_point_min_dis>>8;	//High 3
	buf[cnt++] = C_point_min_dis;			//Low  4
	buf[cnt++] = C_point_min_angle>>8;//High 5
	buf[cnt++] = C_point_min_angle;   //Low  6
	buf[cnt++] = D_point_min_dis>>8;	//High 7
	buf[cnt++] = D_point_min_dis;			//Low  8
	buf[cnt++] = D_point_min_angle>>8;//High 9
	buf[cnt++] = D_point_min_angle;   //Low  10
	buf[cnt++] = CRC8_Table(buf,11);  //11
	buf[cnt++] = 0X19;								//12
	buf[2] = cnt;
	
	runcnt++;
	if(runcnt>3)
	{
		send_data_dma_u1(buf,cnt);
		runcnt = 0;
	}
}



extern float lidar_dis[4];   
extern float lidar_angle[4];

float lidar3_a_mindis = 0,lidar3_b_mindis = 0;
float lidar3_a_minangle = 0,lidar3_b_minangle = 0;
void RF433_Data_Decode(uint8_t *buf)
{
	uint8_t crc8 = 0;
	//Receive Data from the Board3..
	if(buf[0]==0XF1&&buf[1]==0X01&&buf[2]==0X0D&&buf[12]==0X19)
	{
		//Get CRC Value..
		crc8 = buf[11];
		
		//CRC8 Check..
		if(CRC8_Table_Check(buf,11,crc8))
		{
			//A2A3,X Arix..refer to lidar_dis[3] Cpd..
			lidar3_a_mindis = ((uint16_t)buf[3]<<8|buf[4]);
			lidar3_a_minangle = ((uint16_t)buf[5]<<8|buf[6]);
			lidar_dis[3] = lidar3_a_mindis;
			lidar_angle[3] = lidar3_a_minangle;
			
			//A1A2,Y Arix..refer to lidar_dis[2] Dpd..
			lidar3_b_mindis = ((uint16_t)buf[7]<<8|buf[8]);
			lidar3_b_minangle = ((uint16_t)buf[9]<<8|buf[10]);
			lidar_dis[2] = lidar3_b_mindis;
			lidar_angle[2] = lidar3_b_minangle;
		}
	}
}

